package cn.test;

import org.json.JSONObject;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class App {

    public static String status = "init";

    public static void main(String[] args) throws Exception {
        Synthesizer synthesizer = Synthesizer.getInstance();
        Recognizer recognizer = Recognizer.getInstance();
        AIPClient aipClient = AIPClient.getInstance();

        //1.合成语音:因为远程不能语音录入,所以采用文字合成语音至文件Config.VOICEFILE
        synthesizer.systhesizerToVoice(Config.TEXT2BESYNTHESIZER, Config.VOICEFILE);
        while(status != "synthesizerCompleted"){
            System.out.println("1:"+status+":语音合成中...");
        }
        //2.语音听写:从Config.VOICEFILE语音文件中听写的内容转成文字写入Config.TXTFILE文件
        recognizer.recognizerFromFile(Config.VOICEFILE);
        while(status != "recognizerCompleted"){
            System.out.println("2:"+status+":语音听写中...");
        }
        //3.比较相似度
        System.out.println("3:相似度比较中...");
        //读取Config.TXTFILE文件
        String srcStr = Utils.readSrcStr();
        //读取src/main/resources下的所有txt文件,并切分成句子
        String[] tarStrs = Utils.readTarStr();
        //比较srcStr与tarStrs中所有句子的相似度,并返回相似度得分最高的前三个
        JSONObject[] arr = Utils.similar(srcStr, tarStrs, aipClient);
        for (JSONObject jobj:arr) {
            System.out.println(jobj.toString());
        }
    }

}
